<template>
  <el-input
    type="textarea"
    :model-value="fullText"
    placeholder="请输入其他规则限制"
    @input="inputChange"
  ></el-input>
</template>

<script setup>
// const emit = defineEmits();
const props = defineProps({
  modelValue: [String, Array],
});
const fullText = computed({
  get() {
    console.log("gettted");
    return formatterRichText(props.modelValue);
  },
  set(value) {
    // console.log(value, "setter");
    // emit("upate:modelValue", parserRichText(value));
  },
});

// 将数组转换为字符串，每个元素后加回车
const formatterRichText = (value) => {
  console.log(value);
  if (Array.isArray(value)) {
    return value.map((v) => v.content).join("\n");
  }
  return value;
};
const inputChange = (value) => {
  console.log(value);
  // emit("upate:modelValue", parserRichText(value));
  console.log(fullText);
};
// 将字符串按回车分割成数组
const parserRichText = (value) => {
  const lines = value
    .split(/\r?\n|\r/)
    .map((line) => ({ note_type: 1, content: line }));
  // 过滤掉空行
  const filteredLines = lines.filter((line) => line.content.trim() !== "");
  console.log(filteredLines);
  // parsedValue.value = filteredLines;
  return filteredLines;
};
</script>

<style lang="scss" scoped></style>
